#/usr/bin/python
# -*- coding: utf-8 -*-
'''

NOTE: voir femio.py dans le dossier Conception.

...

Created on 6 mars 2012

@author: Ludovic Barrière and Steven Marguet, Institut Clément Ader, 135 av. de Rangueil, 31077 Toulouse, France

© copyright:
    
    TODO
'''


#import domain
#import mesh
#import stepManager
#import re
#import os
import sys
sys.path.append('../../../icafe')
import parameters
from parserAbaqus import Parser as pa
from parserPatran import Parser as pp       

# Model Parser class:
class ModelParser():
      
    def __init__(self, filename):
        
        _extension = filename.split('.')[-1]
        
        try:
            self.parser = FORMAT_TO_PARSER[_extension](filename)
        except KeyError:
            print "No parser for file with extension .", _extension
        
        self.domain = None
        self.analysis = None
        self.stepManager = None
    
    def readFile(self):
        
        self.parser.read()
        self.domain, self.analysis, self.stepManager = self.parser.buildModel()
    
    def writeFile(self,outFileName=None):
        
        self.parser.buildData()
        self.parser.write(outFileName)
        
    
    def buildModel(self):
        return self.reader.buildModel()
        
#    def set_mesh(self, MESH):
#        return self.reader.set_mesh(MESH)
#    
#    def get_mesh(self):
#        return self.reader.get_mesh()
#    
#    def set_st_mngr(self,ST_MNGR):
#        return self.reader.set_st_mngr(ST_MNGR)
#    
#    def get_st_mngr(self):
#        return self.reader.get_st_mngr()


FORMAT_TO_PARSER = {
            "inp": pa,
            "bdf": pp,
            "dat": pp,        
    }   
  
  
        
#def read_file(filename,DOMAIN = None, MESH = None, ST_MNGR = None):
#    
#    if not DOMAIN:
#        DOMAIN = domain.Domain()
#    if MESH == None:
#        MESH = mesh.Mesh()
#    if ST_MNGR == None:
#        ST_MNGR = stepManager.StepManager()
#    
#    _extension = filename.split('.')[-1]
#        
#    try:
#        ifr = FORMAT_TO_READER[_extension](filename)
#    except KeyError:
#        print "No reader for file with extension .", _extension
#    
#    ifr.set_mesh(MESH)
#    ifr.set_st_mngr(ST_MNGR)
#    ifr.read_file()
#    
#    MESH = ifr.get_mesh()
#    ST_MNGR = ifr.get_st_mngr()
#    
#    MESH.consolidateMesh()
#    
#    print DOMAIN.addMesh(MESH, "INITIAL")
#    
#    del ifr
#    
#    
#    
#    return DOMAIN, MESH, ST_MNGR


if __name__ == "__main__":
    
    #D, M, S = read_file('monfichier.inp')

    #D = domain.GlobalDomain(D)
    pass

